home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / vc / pro16 / lshow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-25  |  20.8 KB  |  604 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <fcntl.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include"include\L_Bitmap.h"
  7. #include"include\L_error.h"
  8. #include"include\L_toolap.h"  
  9.  
  10. #define OK 1
  11. #define BAD_COMMAND -2
  12. #define TARGAOLD 1
  13. #define VGA   2
  14.  
  15. int mode,page;
  16. int Width=0,Height=0,Xorigin=-1,Yorigin=-1;
  17. int time=0;
  18. int video=VGA;
  19. int device_bits;
  20. char infile[400];
  21.  
  22.  
  23. main(int argc, char *argv[])
  24. {
  25.   FILE *Stream;
  26.   FILEINFO FileInformation;
  27.   char command[400], commandln[400];
  28.   struct find_t file;
  29.   int result;
  30.   int i;
  31.   char string[400], pathname[400];
  32.   int lines=0;
  33.   int error;
  34.   int first_option = 0;
  35.   int position, position1, kk;
  36.   char path[200];
  37.  
  38.   strcpy(path, argv[0]);
  39.  
  40.    L_SetDecompressFormatJTIF();
  41.    L_SetDecompressFormatJFIFCMP();
  42.  
  43.  
  44.   for (i = strlen(path)-1; i > 0; i--)
  45.    {
  46.    if (path[i] == '\\' || path[i] == ':')
  47.       break;
  48.    }
  49.      path[i+1] = 0;
  50.   i=0;
  51.  
  52.   #if !defined(FOR_386)
  53.   /**** load the fixed palette table to memory ****/
  54.   if ( L_LoadFixedPalette(path) != SUCCESS)
  55.     {
  56.       puts("Error: cannot load FIXEDPAL.DAT file.\n");
  57.       putch(7);
  58.       exit(0);
  59.     }
  60.   #endif
  61.               
  62.   L_GetVideoMode(&mode,&page);
  63.  
  64.   L_SetCheckStatus(NO_CHECK);
  65.  
  66.   if(argc<=1)
  67.   {
  68.      printf("\n                     LEADTOOLS DOS EVAL copy V 2.2\n");
  69.      printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  70.      printf("              8701 Mallard Creek Rd.\n");
  71.      printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  72.      printf("\nDOS 32 - File to screen software deompression utility Version 3.4\n");
  73.      printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  74.      L_SleepKey(2);
  75.      printf("USAGE: LSHOW <@macro file name>\n");
  76.      printf("or      LSHOW <source file> [/option1] [/option2] [/option3] [/option4]\n");
  77.      printf("                              [/option5] [/option6]\n\n");
  78.      printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  79.      printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  80.      printf("                  or TGA, TIFF, or BMP file formats\n");
  81.  
  82. #ifdef TARGA
  83.      printf("[option1] /TA for TARGA16, TARGA24, or TARGA32\n");
  84. #else
  85.      printf("[option1] /TA for TARGA+16, TARGA+32, TARGA+64\n");
  86. #endif
  87.      printf(" or       /V320  display to FAST SUPER VGA 320X200\n");
  88.      printf("          /V640  display to FAST SUPER VGA 640X480\n");
  89.      printf("          /V800  display to FAST SUPER VGA 800X600\n");
  90.      printf("          /V1024 display to FAST SUPER VGA 1024X768\n");
  91.      printf("[option2] /W# the New Width of the image displayed on the screen\n");
  92.      printf("[option3] /H# the New Height of the image displayed on the screen\n");
  93.      printf("[option4] /T# number of seconds to keep image displayed on the screen\n");
  94.      printf("[option5] /X# the X (horizontal) position of the image displayed on the screen\n");
  95.      printf("[option6] /Y# the Y (vertical) position of the image displayed on the screen\n\n");
  96.      printf("EXAMPLE LSHOW *.* /W300 /H200 /T4 /X20 /Y20\n");
  97.      printf("Will display all image files to the VGA/SuperVGA screen at the best resolution\nfor the selected image file\n");
  98.      exit(0);
  99.   }
  100.    strcpy(string,argv[1]);
  101.    get_pathname(argv[1], pathname);
  102.    if(argv[1][0]=='@')
  103.     {
  104.      i=0;
  105.      while(string[i])
  106.       {
  107.       pathname[i]=string[i+1];
  108.       i++;
  109.       }
  110.      pathname[i]= '\0';
  111.      if(Stream=fopen(pathname,"r"))
  112.       {
  113.        while(fgets(commandln, 400, Stream) != NULL)
  114.          {
  115.           Width = 0; Height = 0;
  116.           Xorigin = 0; Yorigin = 0;
  117.           first_option = 0;
  118.           position = 0;
  119.           while(sscanf(commandln+position,"%s",command)!=EOF)
  120.              {
  121.               position1 = strlen(command);
  122.               if( (position1 == 0) || (command[0]=='#') )
  123.                  break;
  124.               position = position + position1;
  125.               strupr(command);
  126.               if(command[0]=='/')
  127.                {
  128.                 get_value(command+1);
  129.                 first_option = 1;
  130.                }
  131.               else if (first_option == 0)
  132.                {
  133.                 
  134.                    strcpy(infile,command);
  135.                    getfilename(infile);
  136.                    first_option = 1;
  137.                }
  138.               else
  139.                {
  140.                 L_SetVideoMode(mode,page);
  141.                 printf("Error: invalid macro line %s\n",commandln);
  142.                 exit(0);
  143.                }
  144.               for (kk = position; kk < strlen(commandln); kk++)
  145.                   {
  146.                   if (commandln[kk] == 0x0d || commandln[kk] == 0x0a)
  147.                      {
  148.                      position1 = 0;
  149.                      break;
  150.                      }
  151.  
  152.                   if (commandln[kk] > 32)
  153.                      break;
  154.                   }
  155.  
  156.               position = kk;
  157.               if (position1 == 0)
  158.                  break;
  159.              }
  160.             if(infile[0]!='\0')
  161.             {
  162.  
  163.              if(video==VGA)
  164.                {
  165.                 L_GetVideoDeviceBits(&device_bits);
  166.                 if (L_FileInfo(infile, &FileInformation)==SUCCESS)
  167.                  {
  168.                   if( FileInformation.Format == FILE_TGA)
  169.                    {
  170.                      #if !defined(FOR_386)
  171.                      if(FileInformation.BitsPerPixel > 8)
  172.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  173.                        {
  174.                         L_SetVideoMode(mode,page);
  175.                         puts("Error: cannot load FIXED.DAT file.\n");
  176.                         putch(7);
  177.                         exit(0);
  178.                        }
  179.                      #endif
  180.  
  181.                       error=L_ShowTGAScreen(infile,Width,Height,Xorigin,Yorigin);
  182.  
  183.                      #if !defined(FOR_386)
  184.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  185.                        L_FreeRGBFixedPalette();
  186.                      #endif
  187.  
  188.                    }
  189.                   else if( FileInformation.Format == FILE_TIF)
  190.                    {
  191.                      #if !defined(FOR_386)
  192.                      if(FileInformation.BitsPerPixel > 8)
  193.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  194.                        {
  195.                         L_SetVideoMode(mode,page);
  196.                         puts("Error: cannot load FIXED.DAT file.\n");
  197.                         putch(7);
  198.                         exit(0);
  199.                        }
  200.                      #endif
  201.  
  202.                      error=L_ShowTIFScreen(infile,Width,Height,Xorigin,Yorigin);
  203.                      #if !defined(FOR_386)
  204.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  205.                        L_FreeRGBFixedPalette();
  206.                      #endif
  207.                    }
  208.                   else if( (FileInformation.Format == FILE_BMP) || (FileInformation.Format == FILE_OS2) )
  209.                    {
  210.                      #if !defined(FOR_386)
  211.                      if(FileInformation.BitsPerPixel > 8)
  212.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  213.                        {
  214.                         L_SetVideoMode(mode,page);
  215.                         puts("Error: cannot load FIXED.DAT file.\n");
  216.                         putch(7);
  217.                         exit(0);
  218.                        }
  219.                      #endif
  220.  
  221.                       error=L_ShowBMPScreen(infile,Width,Height,Xorigin,Yorigin);
  222.  
  223.                      #if !defined(FOR_386)
  224.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  225.                        L_FreeRGBFixedPalette();
  226.                      #endif
  227.  
  228.                    }
  229.                   else if( FileInformation.Format == FILE_PCX)
  230.                    {
  231.                      #if !defined(FOR_386)
  232.                      if(FileInformation.BitsPerPixel > 8)
  233.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  234.                        {
  235.                         L_SetVideoMode(mode,page);
  236.                         puts("Error: cannot load FIXED.DAT file.\n");
  237.                         putch(7);
  238.                         exit(0);
  239.                        }
  240.                      #endif
  241.  
  242.                      error=L_ShowPCXScreen(infile,Width,Height,Xorigin,Yorigin);
  243.  
  244.                      #if !defined(FOR_386)
  245.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  246.                        L_FreeRGBFixedPalette();
  247.                      #endif
  248.  
  249.                    }
  250.                   else if( FileInformation.Format == FILE_GIF)
  251.                    {
  252.                       error=L_ShowGIFScreen(infile,Width,Height,Xorigin,Yorigin);
  253.                    }
  254.                   else if( (FileInformation.Format == FILE_CMP) || (FileInformation.Format == FILE_JTIF)
  255.                            || ( FileInformation.Format == FILE_JFIF) )
  256.                    {
  257.                      #if !defined(FOR_386)
  258.                       error=L_DecompressVGAScreenFP(infile, Width, Height, Xorigin,Yorigin);
  259.                      #else
  260.                       error=L_DecompressVGAScreen(infile, Width, Height, Xorigin,Yorigin);
  261.                      #endif
  262.                    }
  263.                   if( (time>1) )
  264.                     L_SleepKey(time);
  265.                  }
  266.                }
  267.               else if(video==TARGAOLD)
  268.                {
  269.                  error=L_DecompressTARGAScreen(infile,0,0,Xorigin,Yorigin);
  270.                  if( (time>1) )
  271.                     L_SleepKey(time);
  272.                }
  273.             }
  274.           time=0;
  275.          infile[0]='\0';
  276.          }/*end while reading*/
  277.            L_SetVideoMode(mode,page);
  278.            exit(0);
  279.       }/*if*/
  280.      else
  281.       {
  282.        printf("Error: could not open macro file %s\n",pathname);
  283.        exit(0);
  284.       }
  285.    }
  286.   else
  287.    {
  288.     for (i = 2; i<=argc; i++)
  289.       {
  290.         strupr(argv[i]);
  291.         if(argv[i][0]=='/')
  292.           if(get_value(&argv[i][1])==BAD_COMMAND)
  293.             {
  294.               printf("\n                     LEADTOOLS DOS EVAL copy V 2.2");
  295.               printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  296.               printf("              8701 Mallard Creek Rd.\n");
  297.               printf("              Charlotte NC 28262\n");
  298.               printf("              tel# (704)549-5532\n");
  299.               printf("\nDOS - File to screen software deompression utility Version 3.4\n");
  300.               printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  301.               L_SleepKey(2);
  302.               printf("USAGE: LSHOW <source file> [/option1] [/option2] [/option3] [/option4]\n");
  303.               printf("                              [/option5] [/option6]\n\n");
  304.               printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  305.               printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  306.               printf("                  or TGA, TIFF, or BMP file formats\n");
  307.  
  308. #ifdef  TARGA
  309.               printf("[option1] /TA for TARGA16, TARGA24, or TARGA32\n");
  310. #else
  311.               printf("[option1] /TA for TARGA+16, TARGA+32, TARGA+64\n");
  312. #endif
  313.               printf(" or       /V320  display to FAST SUPER VGA 320X200\n");
  314.               printf("          /V640  display to FAST SUPER VGA 640X480\n");
  315.               printf("          /V800  display to FAST SUPER VGA 800X600\n");
  316.               printf("          /V1024 display to FAST SUPER VGA 1024X768\n");
  317.               printf("[option2] /W# the New Width of the image displayed on the screen\n");
  318.               printf("[option3] /H# the New Height of the image displayed on the screen\n");
  319.               printf("[option4] /T# number of seconds to keep image displayed on the screen\n");
  320.               printf("[option5] /X# the X (horizontal) position of the image displayed on the screen\n");
  321.               printf("[option6] /Y# the Y (vertical) position of the image displayed on the screen\n\n");
  322.               printf("EXAMPLE LSHOW *.* /W300 /H200 /T4 /X20 /Y20\n");
  323.               printf("Will display all image files to the VGA/SuperVGA screen at the best resolution\nfor the selected image file\n\n\n");
  324.               printf("BAD COMMAND %s\n",argv[i-1]);
  325.                exit(0);
  326.             }/* end if getvalue*/
  327.       }/*end for*/
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.     result = _dos_findfirst(argv[1], 0 , &file);
  335.     if (result)   /* if result has any value rather that 0 then  */
  336.        printf("LSHOW: no such file %s\n",argv[1]);
  337.     else
  338.          while(!result)  /* Stop when _dos_findnext returns */
  339.         {
  340.            strcpy(infile, pathname);
  341.            strcat(infile, file.name);
  342.              if(video==VGA)
  343.                {
  344.                 L_GetVideoDeviceBits(&device_bits);
  345.                 if (L_FileInfo(infile, &FileInformation)==SUCCESS)
  346.                  {
  347.                   if( FileInformation.Format == FILE_TGA)
  348.                    {
  349.  
  350.                      #if !defined(FOR_386)
  351.                      if(FileInformation.BitsPerPixel > 8)
  352.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  353.                        {
  354.                         L_SetVideoMode(mode,page);
  355.                         puts("Error: cannot load FIXED.DAT file.\n");
  356.                         putch(7);
  357.                         exit(0);
  358.                        }
  359.                      #endif
  360.  
  361.                       error=L_ShowTGAScreen(infile,Width,Height,Xorigin,Yorigin);
  362.  
  363.                      #if !defined(FOR_386)
  364.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  365.                        L_FreeRGBFixedPalette();
  366.                      #endif
  367.                    }
  368.                   else if( FileInformation.Format == FILE_TIF)
  369.                    {
  370.                      #if !defined(FOR_386)
  371.                      if(FileInformation.BitsPerPixel > 8)
  372.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  373.                        {
  374.                         L_SetVideoMode(mode,page);
  375.                         puts("Error: cannot load FIXED.DAT file.\n");
  376.                         putch(7);
  377.                         exit(0);
  378.                        }
  379.                      #endif
  380.  
  381.                       error=L_ShowTIFScreen(infile,Width,Height,Xorigin,Yorigin);
  382.  
  383.                      #if !defined(FOR_386)
  384.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  385.                        L_FreeRGBFixedPalette();
  386.                      #endif
  387.  
  388.                    }
  389.                   else if( (FileInformation.Format == FILE_BMP) || (FileInformation.Format == FILE_OS2) )
  390.                    {
  391.                      #if !defined(FOR_386)
  392.                      if(FileInformation.BitsPerPixel > 8)
  393.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  394.                        {
  395.                         L_SetVideoMode(mode,page);
  396.                         puts("Error: cannot load FIXED.DAT file.\n");
  397.                         putch(7);
  398.                         exit(0);
  399.                        }
  400.                       #endif
  401.  
  402.                       error=L_ShowBMPScreen(infile,Width,Height,Xorigin,Yorigin);
  403.  
  404.                      #if !defined(FOR_386)
  405.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  406.                        L_FreeRGBFixedPalette();
  407.                      #endif
  408.                    }
  409.                   else if( FileInformation.Format == FILE_PCX)
  410.                    {
  411.                      #if !defined(FOR_386)
  412.                      if(FileInformation.BitsPerPixel > 8)
  413.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  414.                        {
  415.                         L_SetVideoMode(mode,page);
  416.                         puts("Error: cannot load FIXED.DAT file.\n");
  417.                         putch(7);
  418.                         exit(0);
  419.                        }
  420.                       #endif
  421.  
  422.                       error=L_ShowPCXScreen(infile,Width,Height,Xorigin,Yorigin);
  423.  
  424.                      #if !defined(FOR_386)
  425.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  426.                        L_FreeRGBFixedPalette();
  427.                      #endif
  428.  
  429.                    }                
  430.                   else if( FileInformation.Format == FILE_GIF)
  431.                    {
  432.                       error=L_ShowGIFScreen(infile,Width,Height,Xorigin,Yorigin);
  433.                    }
  434.                   else if( (FileInformation.Format == FILE_CMP) || (FileInformation.Format == FILE_JTIF)
  435.                            || ( FileInformation.Format == FILE_JFIF) )
  436.                    {
  437.                      #if !defined(FOR_386)
  438.                        error=L_DecompressVGAScreenFP(infile, Width, Height, Xorigin,Yorigin);
  439.                      #else
  440.                        error=L_DecompressVGAScreen(infile, Width, Height, Xorigin,Yorigin);
  441.                      #endif
  442.                    }
  443.                   if( (time>1) )
  444.                     L_SleepKey(time);
  445.                  }
  446.                }
  447.                else if(video==TARGAOLD)
  448.                 {
  449.                   printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  450.                   printf("              8701 Mallard Creek Rd.\n");
  451.                   printf("              Charlotte NC 28262\n");
  452.                   printf("              tel# (704)549-5532\n");
  453.                   printf("\nDOS - File to screen software deompression utility Version 3.4\n");
  454.  #ifdef TARGA
  455.                   printf("Viewing image file %s to TARGA screen",file.name);
  456.  
  457.  #else
  458.                   printf("Viewing image file %s to TARGA+ screen",file.name);
  459.  #endif
  460.                    error=L_DecompressTARGAScreen(infile,0,0,Xorigin,Yorigin);
  461.              
  462.                 if((time >1))
  463.                    L_SleepKey(time);
  464.                  else if (error != SUCCESS)
  465.                    {
  466.                       printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  467.                       printf("              8701 Mallard Creek Rd.\n");
  468.                       printf("              Charlotte NC 28262\n");
  469.                       printf("              tel# (704)549-5532\n");
  470.                       printf("\nDOS - File to screen software deompression utility Version 3.4\n");
  471.                       printf("ERROR %d VIEWING IMAGE FILE %s\n",error,file.name);
  472.                       L_SleepKey(2);
  473.                    }
  474.                 }
  475.           result = _dos_findnext(&file);
  476.         }
  477. L_SetVideoMode(mode,page);
  478. }/*else*/
  479. exit(0);
  480. }
  481.  
  482.  
  483.  
  484. get_value(char *string)
  485. {
  486.  int ret=OK;
  487.  
  488.  if (string[0] == 'X')
  489.   {
  490.      Xorigin = atoi(string+1);
  491.      if (Xorigin < 0 || Xorigin > 1024)
  492.         return(BAD_COMMAND);
  493.      else
  494.         return(ret);
  495.   }
  496.  
  497.  if (string[0] == 'Y')
  498.   {
  499.      Yorigin = atoi(string+1);
  500.      if (Yorigin < 0 || Yorigin > 1024)
  501.         return(BAD_COMMAND);
  502.      else
  503.         return(ret);
  504.   }
  505.  
  506.  if (string[0] == 'T' && string[1] != 'A')
  507.   {
  508.      time = atoi(string+1);
  509.      if (time < 0)
  510.         return(BAD_COMMAND);
  511.      else
  512.         return(ret);
  513.   }
  514.  
  515.  if (string[0] == 'w' || string[0] == 'W')
  516.   {
  517.      Width = atoi(string+1);
  518.      if (Width < 0)
  519.         return(BAD_COMMAND);
  520.      else
  521.         return(ret);
  522.   }
  523.  
  524.  if (string[0] == 'h' || string[0] == 'H')
  525.   {
  526.      Height = atoi(string+1);
  527.      if (Height < 0)
  528.         return(BAD_COMMAND);
  529.      else
  530.         return(ret);
  531.   }
  532.  
  533.  if (string[0] == 'T' && string[1] == 'A')
  534.   {
  535.      video=TARGAOLD;
  536.      if(L_TARGAInit()==0)
  537.       {
  538. #ifdef TARGA
  539.          printf("TARGA Initialization error\n\n");
  540. #else
  541.          printf("TARGA+ Initialization error\n\n");
  542. #endif     
  543.          exit(0);
  544.       }
  545.   }
  546.  
  547.  if(string[0] == 'V')
  548.   {
  549.      video=VGA;
  550.      if(strstr(string,"V320"))
  551.         {
  552.         L_SetVideoMode(mode,page);
  553.         L_SetVGASize(SIZE_320x200);
  554.         }  
  555.      else if(strstr(string,"V640"))
  556.         {
  557.         L_SetVideoMode(mode,page);
  558.         L_SetVGASize(SIZE_640x480);
  559.         }  
  560.      else if(strstr(string,"V800"))
  561.         {
  562.         L_SetVideoMode(mode,page);
  563.         L_SetVGASize(SIZE_800x600);
  564.         }  
  565.      else if(strstr(string,"V1024"))
  566.         {
  567.         L_SetVideoMode(mode,page);
  568.         L_SetVGASize(SIZE_1024x768);
  569.         }  
  570.   }
  571.  return(ret);
  572. }
  573.  
  574.  
  575.  
  576. get_pathname(char in[], char pathname[])
  577. {
  578.  int i;
  579.  
  580.  strcpy(pathname, in);
  581.  for (i = strlen(in)-1; i >= 0; i--)
  582.   {
  583.     if( (in[i] == '\\') || (in[i] == ':') )
  584.       break;
  585.   }
  586.  
  587.  if (i == 0)
  588.     pathname[0] = 0;
  589.  else
  590.     pathname[i+1] = 0;
  591. }
  592.  
  593.  
  594. getfilename(char * name)
  595. {
  596.    int i=0;
  597.  
  598.    while(name[i]!=' ')
  599.       {
  600.        i++;
  601.       }
  602.    name[i]=='\0';
  603. }
  604.